from config.config import get_settings
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from common.enums import DbEnum


def get_db():
    """
    每一个请求处理完毕后会关闭当前连接，不同的请求使用不同的连接
    :return:
    """

    url = get_settings().databases[DbEnum.DB_MASTER.value]['url']
    engine = create_engine(
        url, echo=True
    )
    SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
    db = SessionLocal()
    return db
    # try:
    #     yield db
    # finally:
    #     db.close()


mdb = get_db()
